package com.example.shell.command;

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;

@ShellComponent
public class MyCommands {

    @ShellMethod(value = "Add two numbers.", key = "add")
    public int add(
            @ShellOption(defaultValue = "0") int a,
            @ShellOption(defaultValue = "0") int b) {
        return a + b;
    }
    
    @ShellMethod(value = "Say hello to someone.", key = "hello")
    public String hello(
            @ShellOption(defaultValue = "World") String name) {
        return "Hello, " + name + "!";
    }

    @ShellMethod("User management command")
    public String user(
            @ShellOption(value = {"-n", "--name"}, help = "User name") String name,
            @ShellOption(value = {"-a", "--age"}, defaultValue = "18", help = "User age") int age,
            @ShellOption(value = {"-r", "--role"}, defaultValue = "USER", help = "User role") String role,
            @ShellOption(value = {"-e", "--enable"}, defaultValue = "true", help = "Is user enabled") boolean enabled) {

        return String.format("User created: name=%s, age=%d, role=%s, enabled=%b",
                name, age, role, enabled);
    }
}
